package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.TrPson;
import com.ruoyi.system.mapper.TrPsonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TrAffairMapper;
import com.ruoyi.system.domain.TrAffair;
import com.ruoyi.system.service.ITrAffairService;

/**
 * 事件编号Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-26
 */
@Service
public class TrAffairServiceImpl implements ITrAffairService 
{
    @Autowired
    private TrAffairMapper trAffairMapper;


    @Autowired
    private TrPsonMapper trPsonMapper;

    /**
     * 查询事件编号
     * 
     * @param affairId 事件编号主键
     * @return 事件编号
     */
    @Override
    public TrAffair selectTrAffairByAffairId(Long affairId)
    {
        return trAffairMapper.selectTrAffairByAffairId(affairId);
    }

    /**
     * 查询事件编号列表
     * 
     * @param trAffair 事件编号
     * @return 事件编号
     */
    @Override
    public List<TrAffair> selectTrAffairList(TrAffair trAffair)
    {
        List<TrAffair> trAffairs = trAffairMapper.selectTrAffairList(trAffair);
        for (TrAffair affair : trAffairs) {

            StringBuilder affairPsonName = new StringBuilder();
            String[] psonIdS = affair.getAffairPson().split(",");

            for (String psonId : psonIdS) {

                TrPson trPson = trPsonMapper.selectTrPsonByPsonId(Long.parseLong(psonId));

                if (trPson != null) {
                    affairPsonName.append(trPson.getPsonName()).append(",");
                }
            }


            affair.setAffairPsonName(affairPsonName.toString());


        }
        return trAffairs;
    }

    /**
     * 新增事件编号
     * 
     * @param trAffair 事件编号
     * @return 结果
     */
    @Override
    public int insertTrAffair(TrAffair trAffair)
    {
        trAffair.setCreateTime(DateUtils.getNowDate());
        return trAffairMapper.insertTrAffair(trAffair);
    }

    /**
     * 修改事件编号
     * 
     * @param trAffair 事件编号
     * @return 结果
     */
    @Override
    public int updateTrAffair(TrAffair trAffair)
    {
        trAffair.setUpdateTime(DateUtils.getNowDate());
        return trAffairMapper.updateTrAffair(trAffair);
    }

    /**
     * 批量删除事件编号
     * 
     * @param affairIds 需要删除的事件编号主键
     * @return 结果
     */
    @Override
    public int deleteTrAffairByAffairIds(Long[] affairIds)
    {
        return trAffairMapper.deleteTrAffairByAffairIds(affairIds);
    }

    /**
     * 删除事件编号信息
     * 
     * @param affairId 事件编号主键
     * @return 结果
     */
    @Override
    public int deleteTrAffairByAffairId(Long affairId)
    {
        return trAffairMapper.deleteTrAffairByAffairId(affairId);
    }
}
